package 每日一题;

/**
 * @author 会玩的洋洋
 * https://leetcode-cn.com/problems/optimal-division/
 */
public class _553_最优除法 {
    public String optimalDivision(int[] nums) {
        if (nums.length == 1) {
            return String.valueOf(nums[0]);
        } else if (nums.length == 2) {
            return nums[0] + "/" + nums[1];
        }

        StringBuilder sb = new StringBuilder();
        sb.append(nums[0]).append("/").append("(");
        for (int i = 1; i < nums.length; i++) {
            if (i < nums.length - 1) {
                sb.append(nums[i]).append("/");
            } else {
                sb.append(nums[i]);
            }
        }
        sb.append(")");
        return sb.toString();
    }
}
